﻿#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>

MainWindow::MainWindow(QWidget* parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
    , m_SideBrowser(nullptr)
    , m_pTopTool(nullptr)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);    // 取消标题栏

    QVBoxLayout *pLayout = new QVBoxLayout;
    ui->centralwidget->setLayout(pLayout);
    pLayout->setSpacing(0);
    pLayout->setContentsMargins(0, 0, 0, 0);

    m_pTopTool = new TopTitle(this);
    pLayout->addWidget(m_pTopTool);

    m_SideBrowser = new SideBrowser(this);
    pLayout->addWidget(m_SideBrowser);

    connect(m_pTopTool, SIGNAL(click_expand()), this, SLOT(slt_expand()));
    connect(m_pTopTool, SIGNAL(click_closeWindow()), this, SLOT(slt_closeWindow()));
    connect(m_pTopTool, SIGNAL(click_resizeWindow()), this, SLOT(slt_resizeWindow()));
    connect(m_pTopTool, SIGNAL(click_showTabs()), this, SLOT(slt_showTabIndex()));
    connect(m_SideBrowser, SIGNAL(showPageTitle(QString)), this, SLOT(slt_setTitleInfo(QString)));

    m_SideBrowser->addTabPage(QString("图片点框绘制"), QString(":/common/resource/common/gallery_image_photo.ico"), FUNC_FORM_PICPROC);
    m_SideBrowser->addTabPage(QString("Base64编解码"), QString(":/common/resource/common/paper_pen_text.ico"), FUNC_FORM_BASE64);
   // m_SideBrowser->addTabPage(QString("图片点框绘制"), QString(":/common/resource/common/gallery_image_photo.ico"), FUNC_FORM_PICPROC);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slt_expand()
{
    if(nullptr != m_SideBrowser)
    {
        m_SideBrowser->changeSideBar();
    }
}

void MainWindow::slt_closeWindow()
{
    this->close();
}

void MainWindow::slt_resizeWindow()
{
    if (isMaximized())
    {
        showNormal(); // 还原窗口大小
    }
    else
    {
        showMaximized(); // 最大化窗口
    }
}

void MainWindow::slt_showTabIndex()
{
    if (nullptr != m_SideBrowser)
    {
        m_SideBrowser->showTabIndex();
    }
}

void MainWindow::slt_setTitleInfo(QString strInfo)
{
    if(nullptr != m_pTopTool)
    {
        m_pTopTool->setTitleInfo(strInfo);
    }
}
